﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair.Base
{
    public partial class frmjiezhang : Form
    {
        public frmjiezhang()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void frmjiezhang_Load(object sender, EventArgs e)
        {
            jzcmb();
            txtxf.Text= chuanzhi.jzys.ToString();
            txthy.Text = chuanzhi.yezf.ToString();
            txtys.Text = (decimal.Parse(txtxf.Text) - decimal.Parse(txtmoling.Text)).ToString();
            txtzhaoling.Text = ((decimal.Parse(txtxj.Text)+decimal.Parse(txtmoling.Text)+ decimal.Parse(txthy.Text)+ decimal.Parse(txtqtzf.Text)) - decimal.Parse(txtys.Text)).ToString();
           
        }
        public void jzcmb()
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string sql = "SELECT [id] ,[zhID] ,[zhname] FROM [yhzh] where zhname!='现金'  ";
            SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
            DataSet ds = new DataSet();
            sda.Fill(ds,"yhzh");
            cmbskfs.DataSource = ds.Tables["yhzh"];
            cmbskfs.DisplayMember = "zhname";
            conn.Close();
        }

        private void txtmoling_TextChanged(object sender, EventArgs e)
        {
            try
            {
                txtys.Text = (decimal.Parse(txtxf.Text) - decimal.Parse(txtmoling.Text)).ToString();
            }
            catch { }
        }

        private void txtxj_TextChanged(object sender, EventArgs e)
        {
            try
            {
                txtzhaoling.Text = ((decimal.Parse(txtxj.Text) + decimal.Parse(txtqtzf.Text) + decimal.Parse(txthy.Text)) - decimal.Parse(txtys.Text)).ToString();
            }
            catch { }
        }

        private void txtqtzf_TextChanged(object sender, EventArgs e)
        {
            try
            {
                txtzhaoling.Text = ((decimal.Parse(txtxj.Text) + decimal.Parse(txtqtzf.Text) + decimal.Parse(txthy.Text)) - decimal.Parse(txtys.Text)).ToString();
            }
            catch { }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            chuanzhi.jzbs = 0;
            if (decimal.Parse(txtzhaoling.Text.Trim()) >= 0)
            {
                chuanzhi.jzbs = 1;
                this.Close();
            }
            else
            {
                MessageBox.Show("清正确选择收款方式或正确填写收款金额！");
            }
        }
    }
}
